# encoding=utf8
import sys
import time
import math
reload(sys)
sys.setdefaultencoding('utf8')

class FT_0791:
    result=[]
    LatStrInfo = ""
    LongStrInfo = ""
    def LogicAisle(self, protocolStr, header):
        count = 0
        s = protocolStr[count:count + 4]
        header.append("自定义消息体长度：" + s+"\n")
        count = count + 4
        s = protocolStr[count:count + 6]
        header.append("行程编号：" + s )
        count=count+6
        s = protocolStr[count:count + 2]
        header.append("序号：" + s+ "\n")
        count = count+2

        s = protocolStr[count:count + 2]
        header.append("行程内序号：" + s + "\n")
        count = count + 2

        s = protocolStr[count:count + 2]
        header.append("行程结束原因 ：" + s  )
        if s=="00":
            header.append("ACC关" + "\n")
        elif s=="01":
            header.append("IG关" + "\n")
        elif s=="02":
            header.append("发动机熄火持续 5 分钟" + "\n")
        elif s=="03":
            header.append("达到半小时上限" + "\n")
        elif s=="04":
            header.append("跨天汇报（需要在 23:59:59 或之前进行汇报）" + "\n")
        count = count + 2

        s = protocolStr[count:count + 12]
        c = 0
        t = s[c:c + 2]
        header.append("行程开始时间：" + t)
        c = c + 2
        for i in range(5):
            t = s[c:c + 2]
            header.append("-" + t)
            c = c + 2
        count = count + 12
        header.append("\n")

        s = protocolStr[count:count + 8]
        self.AnalysisLong(s)
        header.append("开始经度：" + self.LongStrInfo + "度"+"\n")
        count = count + 8
        s = protocolStr[count:count + 8]
        self.AnalysisLat(s)
        header.append("开始纬度：" + self.LatStrInfo + "度"+"\n")
        count = count + 8

        s = protocolStr[count:count + 4]
        n=int(s,16)
        header.append("行程开始海拔：" + str(n) + "米" + "\n")
        count = count + 4

        s = protocolStr[count:count + 8]
        n=int(s,16)*0.1
        header.append("本次行程开始里程：" + str(n) +"公里"+ "\n")
        count = count + 8

        s = protocolStr[count:count + 8]
        n = int(s,16) * 0.5
        header.append("行程开始时累计总油耗：" + str(n) + "L" + "\n")
        count = count + 8

        s = protocolStr[count:count + 12]
        c = 0
        t = s[c:c + 2]
        header.append("行程结束时间：" + t)
        c = c + 2
        for i in range(5):
            t = s[c:c + 2]
            header.append("-" + t)
            c = c + 2
        count = count + 12
        header.append("\n")

        s = protocolStr[count:count + 8]
        self.AnalysisLong(s)
        header.append("结束经度：" + self.LongStrInfo + "度" + "\n")
        count = count + 8
        s = protocolStr[count:count + 8]
        self.AnalysisLat(s)
        header.append("结束纬度：" + self.LatStrInfo + "度" + "\n")
        count = count + 8

        s = protocolStr[count:count + 4]
        n = int(s, 16)
        header.append("行程结束海拔：" + str(n) + "米" + "\n")
        count = count + 4

        s = protocolStr[count:count + 4]
        n = int(s,16)
        header.append("发动机运行时间：" + str(n) + "s" + "\n")
        count = count + 4

        s = protocolStr[count:count + 4]
        n = int(s,16)
        header.append("行程最高海拔：" + str(n) + "米" + "\n")
        count = count + 4

        s = protocolStr[count:count + 4]
        n = int(s,16)
        header.append("行程最低海拔：" + str(n) + "米" + "\n")
        count = count + 4

        s = protocolStr[count:count + 4]
        n = int(s,16)*0.1
        header.append("本次行程行驶里程：" + str(n) + "km" + "\n")
        count = count + 4

        s = protocolStr[count:count + 4]
        n = int(s,16) * 0.1
        header.append("行程总油耗 ：" + str(n) + "L" + "\n")
        count = count + 4

        s = protocolStr[count:count + 4]
        n = int(s,16)
        header.append("怠速运行时间：" + str(n) + "s" + "\n")
        count = count + 4

        s = protocolStr[count:count + 4]
        n = int(s,16) * 0.001
        header.append("行程怠速总油耗:" + str(n) + "L" + "\n")
        count = count + 4

        s = protocolStr[count:count + 4]
        n = int(s,16)
        header.append("刹车累积次数:" + str(n) + "次" + "\n")
        count = count + 4

        s = protocolStr[count:count + 4]
        n = int(s,16)*0.001
        header.append("刹车累计里程:" + str(n) + "km" + "\n")
        count = count + 4

        s = protocolStr[count:count + 4]
        n = int(s,16)
        header.append("刹车累计时间:" + str(n) + "s" + "\n")
        count = count + 4

        s = protocolStr[count:count + 4]
        n = int(s,16)
        header.append("离合累计次数:" + str(n)  + "\n")
        count = count + 4

        s = protocolStr[count:count + 4]
        n = int(s,16)
        header.append("离合累计时间:" + str(n) + "s" + "\n")
        count = count + 4

        s = protocolStr[count:count + 56]
        header.append("车速分布:" + s + "\n")
        count = count + 56

        s = protocolStr[count:count + 88]
        header.append("油门开度分布:" + s + "\n")
        count = count + 88

        s = protocolStr[count:count + 80]
        header.append("转速分布:" + s + "\n")
        count = count + 80

        s = protocolStr[count:count + 88]
        header.append("车辆加速度分布:" + s + "\n")
        count = count + 88
#===================================3.5变更：删除转速负荷矩阵分布、档位分布时间、档位分布里程=======================
       # s = protocolStr[count:count + 400]
       # header.append("转速负荷矩阵分布:" + s + "\n")
       # count = count + 400


       # s = protocolStr[count:count + 104]
       # header.append("档位分布时间:" + s + "\n")
       # count = count + 104

       # s = protocolStr[count:count + 104]
       # header.append("档位分布里程:" + s + "\n")
       # count = count + 104

        s = protocolStr[count:count + 8]
        header.append("载重分布:" + s + "\n")
        count = count + 8

        self.result = header

    def AnalysisLat(self, source):
        #double Lat;
        try:
            Lat = int(source,16) * math.pow(10,-6);
            #self.LatStrInfo = String.format("%.6f", Lat);
            self.LatStrInfo = "%.6f"%Lat
        except:
            pass
    def AnalysisLong(self, source):
        #double Long;
        try:
            Long = int(source,16) * math.pow(10,-6);
            #self.LongStrInfo = String.format("%.6f", Long);
            self.LongStrInfo = "%.6f"%Long
        except:
            pass


